typedef struct{
  char c;
  tree *next, *down;
} tree;

tree *pool = NULL;


tree **lookup(char *s){
  tree **o = &pool, *n;
  while(s){
    while(*o && *s > (n = *o)->c){
      o = &n->next;
    }
    if(*o && *s == (n = *o)->c){
      o = &n->down;
      s++;
    }else{
      n = malloc();
      n->c = *s;
      n->next = *o;
      *o = n;
      o = &n->down;
      s++;
      while(s){
	n = malloc();
	n->c = *s;
	n->next = NULL;
	*o = n;
	o = &n->down;
	s++;
      }
      n->down = NULL;
      break;
    }
  }
  return o;
}
